package com.ruoyi.web.controller.sr;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SrRoom;
import com.ruoyi.system.service.ISrRoomService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 自习室Controller
 * 
 * @author ruoyi
 * @date 2023-04-04
 */
@RestController
@RequestMapping("/system/room")
public class SystemRoomController extends BaseController
{
    @Autowired
    private ISrRoomService srRoomService;

    /**
     * 查询自习室列表
     */
    @PreAuthorize("@ss.hasPermi('system:room:list')")
    @GetMapping("/list")
    public TableDataInfo list(SrRoom srRoom)
    {
        startPage();
        List<SrRoom> list = srRoomService.selectSrRoomList(srRoom);
        return getDataTable(list);
    }

    /**
     * 导出自习室列表
     */
    @PreAuthorize("@ss.hasPermi('system:room:export')")
    @Log(title = "自习室", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SrRoom srRoom)
    {
        List<SrRoom> list = srRoomService.selectSrRoomList(srRoom);
        ExcelUtil<SrRoom> util = new ExcelUtil<SrRoom>(SrRoom.class);
        util.exportExcel(response, list, "自习室数据");
    }

    /**
     * 获取自习室详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:room:query')")
    @GetMapping(value = "/{roomId}")
    public AjaxResult getInfo(@PathVariable("roomId") Long roomId)
    {
        return success(srRoomService.selectSrRoomByRoomId(roomId));
    }

    /**
     * 新增自习室
     */
    @PreAuthorize("@ss.hasPermi('system:room:add')")
    @Log(title = "自习室", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SrRoom srRoom)
    {
        return toAjax(srRoomService.insertSrRoom(srRoom));
    }

    /**
     * 修改自习室
     */
    @PreAuthorize("@ss.hasPermi('system:room:edit')")
    @Log(title = "自习室", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SrRoom srRoom)
    {
        return toAjax(srRoomService.updateSrRoom(srRoom));
    }

    /**
     * 删除自习室
     */
    @PreAuthorize("@ss.hasPermi('system:room:remove')")
    @Log(title = "自习室", businessType = BusinessType.DELETE)
	@DeleteMapping("/{roomIds}")
    public AjaxResult remove(@PathVariable Long[] roomIds)
    {
        return toAjax(srRoomService.deleteSrRoomByRoomIds(roomIds));
    }
}
